$(function() {
	var pageSize = 24, pageNow = 0;
	var divCount = $('#latestList').children('div').length;
	function render(pageSize, pageNow) {
		$
				.ajax({
					'url' : '/expMng/latestList.do',
					'contentType' : "application/json",
					'data' : {
						'pageSize' : pageSize,
						'pageNow' : pageNow
					},
					success : function(data, textStatus, jqXHR) {
						var pagination = data.pagination;
						$('#pagination')
								.pagination(
										{
											'showPageList' : false,
											/* 'loading': true, */
											'total' : pagination.total,
											'displayMsg' : '显示{from} 到 {to} 项，共 {total} 项',
											'pageSize' : pagination.pageSize,
											'pageNumber' : pagination.pageNumber,
											'onSelectPage' : function(
													pageNumber, pageSize) {
												render(pageSize, pageNumber - 1);
											},
											'onRefresh' : function(pageNumber,
													pageSize) {
												render(pageSize, pageNumber - 1);
											},
											'onChangePageSize' : function(
													pageNumber, pageSize) {
												render(pageSize, pageNumber - 1);
											}
										});
						var expPkgs = data.expPkgs;
						$('#latestList').find('div').empty();
						$
								.each(
										expPkgs,
										function(i, v) {
											var keyword = v.keyword;
											var pkgImg = v.pkgImg;
											var mod = i % divCount;
											var pkgImgHtml = '<span class="pkgCls"><img src="/expressions/'
													+ pkgImg
													+ '"/>'
													+ '<a keyword="'
													+ keyword
													+ '", url="/exp/detail.do\"'
													+ ', pageSize="10"'
													+ ', pageNow="0"'
													+ ', href="#">'
													// +'<a
													// href="/expMng/detail.do?pageSize=10&pageNow=0&keyword='+keyword+'">'
													+ keyword + '</a></span>';
											$($('#latestList').find('div')[mod])
													.append(pkgImgHtml);
										})
					}
				});
	}

	function showDetailWin() {
		console.log(this);
		console.log($(this).attr('pageSize'));
		var keyword = $(this).attr('keyword');
		var ul = $(this).attr('url');
		var pageSize = eval($(this).attr('pageSize'));
		var pageNow = eval($(this).attr('pageNow'));
		var title = '<span style="font-size: 20px;color: blue;font-weight: bold;">'
				+ keyword + '</span>';
		$('#detailWind').window({
			'title' : title,
			'width' : 700,
			'height' : 500,
			'modal' : true,
			'closed' : true,
			'closable' : true,
			'zIndex' : 9999,
			'maximizable' : true,
			'minimizable' : false,
			'href': '/expMng/listDetail.do?keyword='+keyword,
			'collapsible' : true
		});
		$('#detailWind').window('open');
	}

	function addDetailPanel(){
		
	}
	
	$('#latestList .column').on('click', 'span>a', showDetailWin);
	render(pageSize, pageNow);
})